from django.db import models

# Create your models here.

class Category(models.Model):
    name = models.CharField('任务分类', max_length=100)
    index = models.IntegerField(default=999, verbose_name='分类排序')

    class Meta:
        verbose_name = '任务分类'
        verbose_name_plural = verbose_name

    def __str__(self):
        return self.name

class Tag(models.Model):
    name = models.CharField('任务标签',max_length=100)
    class Meta:
        verbose_name = '任务标签'
        verbose_name_plural = verbose_name

    def __str__(self):
        return self.name

class TaskStatus(models.Model):
    name = models.CharField('任务状态',max_length=10)
    index = models.IntegerField(default=1,verbose_name='状态排序')

    class Meta:
        verbose_name = '任务状态'
        verbose_name_plural = verbose_name

    def __str__(self):
        return self.name

class Task(models.Model):
    title = models.CharField('任务名称', max_length=100)
    index = models.IntegerField(default=999, verbose_name='任务排序')
    created_time = models.DateTimeField('发布时间', auto_now_add=True)
    task_state = models.ForeignKey(TaskStatus, on_delete= models.DO_NOTHING,verbose_name='任务状态',blank=True,null=True)
    category = models.ForeignKey(Category, on_delete=models.DO_NOTHING, verbose_name='分类', blank=True, null=True)
    #使用外键关联分类表与分类是一对多关系
    tags = models.ManyToManyField(Tag,verbose_name='标签', blank=True)
    #使用外键关联标签表与标签是多对多关系

    class Meta:
        verbose_name = '任务列表'
        verbose_name_plural = verbose_name

    def __str__(self):
        return self.title




class Banner(models.Model):
    text_info = models.CharField('标题', max_length=50, default='')
    img = models.ImageField('轮播图', upload_to='banner/')
    link_url = models.URLField('图片链接', max_length=100)
    is_active = models.BooleanField('是否是active', default=False)

    def __str__(self):
        return self.text_info

    class Meta:
        verbose_name = '轮播图'
        verbose_name_plural = '轮播图'